package com.chenjiahao.kaiyanwan.ui.discovery

import androidx.fragment.app.Fragment
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.chenjiahao.kaiyanwan.logic.dao.Repository
import com.hazz.kotlinmvp.mvp.model.bean.CategoryBean
import com.hazz.kotlinmvp.mvp.model.bean.HomeBean

/**
 * Created by chenjh on 2020/9/17
 */
class DiscoveryViewModel : ViewModel() {
    var fragments = ArrayList<Fragment>()
    var stringTabs = ArrayList<String>()

    private var getFollowInfoLivaData = MutableLiveData<Any?>()
    private var getCategoryLiveData = MutableLiveData<Any?>()
    private var nextPageUrlLiveData = MutableLiveData<String>()

    //关注
    var followNextPageUrl: String? = null
    var followItemList = ArrayList<HomeBean.Issue.Item>()


    val getFollowInfoData = Transformations.switchMap(getFollowInfoLivaData) {
        Repository.getFollowInfo()
    }

    //分类
    var mCategoryList = ArrayList<CategoryBean>()

    val getCategoryInfo = Transformations.switchMap(getCategoryLiveData) {
        Repository.getCategory()
    }

    val getIssueData = Transformations.switchMap(nextPageUrlLiveData) {
        Repository.getIssueData(it)
    }

    fun requestFollow() {
        getFollowInfoLivaData.value = getCategoryInfo.value
    }

    fun requestCategory() {
        getCategoryLiveData.value = getCategoryLiveData.value
    }

    fun requestMoreData() {
        nextPageUrlLiveData.value = followNextPageUrl
    }


}